home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / strfile.zip / STRFILE.C next >
Text File  |  1986-10-14  |  3KB  |  143 lines

  1. /* str file name functions (for Lattice 3.0 port to MSC 4.0) */
  2.  
  3. /* ------------------------------------------------------------ */
  4. /*   copyright 1986:                        */
  5. /*            Nourse Gregg & Browne, Inc.        */
  6. /*            1 Horizon Road. #612            */
  7. /*            Fort Lee, NJ 07024            */
  8. /*                                */
  9. /* ------------------------------------------------------------ */
  10.  
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <stddef.h>
  14.  
  15. #define ZIP '\0'
  16.  
  17. /* ------------------------------------------------------------ */
  18. /*    strsfn   -  split filename into components        */
  19.  
  20.  
  21. void strsfn(file,drive,path,node,ext)
  22.  
  23.     char *file;    /* input:  the whole file name */
  24.     char *drive;    /* output: the drive */
  25.     char *path;    /* output: the sub-directory path */
  26.     char *node;    /* output: the file's base name */
  27.     char *ext;    /* output: the file's extension */
  28.     {
  29.     char *p;
  30.     char fn[64];
  31.  
  32.     strncpy(fn,file,63);
  33.     p=strrchr(fn,'.');    /* find start of extension */
  34.     if (p==NULL) *ext=ZIP;
  35.     else
  36.         {
  37.         *p=ZIP;
  38.         strcpy(ext,p+1);
  39.         }
  40.     p=strrchr(fn,'\\');    /* find end of path */
  41.     if (p==NULL)
  42.         {
  43.         *path=ZIP;
  44.         p=strrchr(fn,':');
  45.         if (p==NULL)
  46.             {
  47.             strcpy(node,fn);
  48.             *drive=ZIP;
  49.             }
  50.         else
  51.             {
  52.             strcpy(node,p+1);
  53.             *(p+1)=ZIP;
  54.             strcpy(drive,fn);
  55.             }
  56.         }
  57.     else
  58.         {
  59.         *p=ZIP;
  60.         strcpy(node,p+1);
  61.         p=strrchr(fn,':');
  62.         if (p==NULL)
  63.             {
  64.             strcpy(path,fn);
  65.             *drive=ZIP;
  66.             }
  67.         else
  68.             {
  69.             strcpy(path,p+1);
  70.             *(p+1)=ZIP;
  71.             strcpy(drive,fn);
  72.             }
  73.         }
  74.     }
  75.  
  76.  
  77.  
  78. /* ------------------------------------------------------------ */
  79. /*    strmfe   -  make filename with new extension        */
  80.  
  81.  
  82. void strmfe(newname,oldname,ext)
  83.  
  84.     char *newname;    /* output: the new file name */
  85.     char *oldname;    /* input:  the old file name */
  86.     char *ext;    /* input:  the new extension */
  87.     {
  88.     char *p;
  89.  
  90.     strcpy(newname,oldname);
  91.     p=strrchr(newname,'.');
  92.     if (p==NULL)
  93.         {
  94.         strcat(newname,".");
  95.         strcat(newname,ext);
  96.         }
  97.     else
  98.         {
  99.         strcpy(p+1,ext);
  100.         }
  101.     }
  102.  
  103.  
  104.  
  105.  
  106. /* ------------------------------------------------------------ */
  107. /*    strmfn   -  make filename from components        */
  108.  
  109.  
  110. void strmfn(file,drive,path,node,ext)
  111.  
  112.     char *file;    /* output: the whole file name */
  113.     char *drive;    /* input:  the drive (or NULL) */
  114.     char *path;    /* input:  the directory path (or NULL) */
  115.     char *node;    /* input:  the file's base name */
  116.     char *ext;    /* input:  the file's extension (or NULL) */
  117.     {
  118.     int i;
  119.  
  120.     *file='\0';
  121.     if (drive!=NULL)
  122.         {
  123.         strcat(file,drive);
  124.         if (file[1]!=':') strcat(file,":");
  125.         }
  126.     if (path!=NULL)
  127.         {
  128.         strcat(file,path);
  129.         i=strlen(file);
  130.         if (file[i-1]!='\\')
  131.             {
  132.             file[i]='\\';
  133.             file[i+1]='\0';
  134.             }
  135.         }
  136.     if (node!=NULL) strcat(file,node);
  137.     if (ext!=NULL)
  138.         {
  139.         strcat(file,".");
  140.         strcat(file,ext);
  141.         }
  142.     }
  143.